/**
 * Created by wangxin on 2017-9-26 10:02:01.
 */

'use strict';
const page = {
    url: {
        loadEventRule: contextData.contextPath + '/work/loadEventRule',
        getCoupon: contextData.contextPath + '/work/getCoupon',
    },
};

page.init = function () {
    page.initElement();
    page.initEvent();
};

page.initElement = function () {
    const thisPage = this;
    Dolphin.ajax({
        url: thisPage.url.loadEventRule,
        type: "get",
        forceUrl: 'true',
        data: {eventId: contextData.data.eventId},
        onSuccess: function (data) {
            $('#coupon').html('立即领取').click(function(){
                Dolphin.ajax({
                    url:thisPage.url.getCoupon,
                    data:{
                        prizeId:data.rule[0]._id,
                        gameType:'getCoupon',
                    },
                    success:function(reData){
                        $.alert(reData.message);
                    }
                });
            })
        },
        onError: function (e) {
            alert('网络出错啦，请您重新加载');
        }
    });
};

page.initEvent = function () {
};

page.formatterDate = function (val, formatter) {
    if(val){
        var date = Dolphin.string2date(val, "yyyy-MM-ddThh:mm:ss.");
        date.setHours(date.getHours() + 8);
        return Dolphin.date2string(date, formatter || "yyyy-MM-dd");
    }else{
        return '';
    }
};

$(function () {
    page.init();
});




